package com.trade.okxserver.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class TreadPoolConfig {


    @Bean("okx-ws")
    public ThreadPoolExecutor threadPoolExecutor() {
        BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>(); // 任务队列
        return new ThreadPoolExecutor(
                16,                  // 核心线程数
                20,                  // 最大线程数
                10,                 // 空闲时间10秒
                TimeUnit.SECONDS,   // 时间单位
                workQueue,         // 任务队列
                new ThreadPoolExecutor.CallerRunsPolicy() // 拒绝策略
        );
    }
}
